Chapter 12. Enabling caching to improve logical volume performance Red Hat Enterprise Linux 8 | 您所在的位置:网站首页 › Adding Cache › Chapter 12. Enabling caching to improve logical volume performance Red Hat Enterprise Linux 8 |
You can add caching to an LVM logical volume to improve performance. LVM then caches I/O operations to the logical volume using a fast device, such as an SSD. The following procedures create a special LV from the fast device, and attach this special LV to the original LV to improve the performance. 12.1. Caching methods in LVMLVM provides the following kinds of caching. Each one is suitable for different kinds of I/O patterns on the logical volume. dm-cacheThis method speeds up access to frequently used data by caching it on the faster volume. The method caches both read and write operations. The dm-cache method creates logical volumes of the type cache. dm-writecacheThis method caches only write operations. The faster volume stores the write operations and then migrates them to the slower disk in the background. The faster volume is usually an SSD or a persistent memory (PMEM) disk. The dm-writecache method creates logical volumes of the type writecache. Additional resources lvmcache(7) man page 12.2. LVM caching componentsLVM provides support for adding a cache to LVM logical volumes. LVM caching uses the following LVM logical volume types: Main LV The larger, slower, and original volume. Cache pool LV A composite LV that you can use for caching data from the main LV. It has two sub-LVs: data for holding cache data and metadata for managing the cache data. You can configure specific disks for data and metadata. You can use the cache pool only with dm-cache. Cachevol LV A linear LV that you can use for caching data from the main LV. You cannot configure separate disks for data and metadata. cachevol can be only used with either dm-cache or dm-writecache.All of these associated LVs must be in the same volume group. You can combine a main logical volume (LV) with a faster, usually smaller, LV that holds the cached data. The fast LV is created from fast block devices, such as SSD drives. When you enable caching for a logical volume, LVM renames and hides the original volumes, and presents a new logical volume that is composed of the original logical volumes. The composition of the new logical volume depends on the caching method and whether you are using the cachevol or cachepool option. The cachevol and cachepool options expose different levels of control over the placement of the caching components: With the cachevol option, the faster device stores both the cached copies of data blocks and the metadata for managing the cache.With the cachepool option, separate devices can store the cached copies of data blocks and the metadata for managing the cache. The dm-writecache method is not compatible with cachepool. In all configurations, LVM exposes a single resulting device, which groups together all the caching components. The resulting device has the same name as the original slow logical volume. Additional resources lvmcache(7) man page Creating and managing thin provisioned volumes (thin volumes) 12.3. Enabling dm-cache caching for a logical volumeThis procedure enables caching of commonly used data on a logical volume using the dm-cache method. Prerequisites A slow logical volume that you want to speed up using dm-cache exists on your system. The volume group that contains the slow logical volume also contains an unused physical volume on a fast block device.Procedure Create a cachevol volume on the fast device: # lvcreate --size cachevol-size --nameReplace the following values: cachevol-size The size of the cachevol volume, such as 5G fastvol A name for the cachevol volume vg The volume group name /dev/fast-pvThe path to the fast block device, such as /dev/sdf Example 12.1. Creating a cachevol volume # lvcreate --size 5G --name fastvol vg /dev/sdf Logical volume "fastvol" created.Attach the cachevol volume to the main logical volume to begin caching: # lvconvert --type cache --cachevolReplace the following values: fastvol The name of the cachevol volume vg The volume group name main-lvThe name of the slow logical volume Example 12.2. Attaching the cachevol volume to the main LV # lvconvert --type cache --cachevol fastvol vg/main-lv Erase all existing data on vg/fastvol? [y/n]: y Logical volume vg/main-lv is now cached.Verification steps Verify if the newly created logical volume has dm-cache enabled: # lvs --all --options +devices LV Pool Type Devices main-lv [fastvol_cvol] cache main-lv_corig(0) [fastvol_cvol] linear /dev/fast-pv [main-lv_corig] linear /dev/slow-pvAdditional resources lvmcache(7) man page 12.4. Enabling dm-cache caching with a cachepool for a logical volumeThis procedure enables you to create the cache data and the cache metadata logical volumes individually and then combine the volumes into a cache pool. Prerequisites A slow logical volume that you want to speed up using dm-cache exists on your system. The volume group that contains the slow logical volume also contains an unused physical volume on a fast block device.Procedure Create a cachepool volume on the fast device: # lvcreate --type cache-pool --size --nameReplace the following values: cachepool-size The size of the cachepool, such as 5G fastpool A name for the cachepool volume vg The volume group name /dev/fastThe path to the fast block device, such as /dev/sdf1 NoteYou can use --poolmetadata option to specify the location of the pool metadata when creating the cache-pool. Example 12.3. Creating a cachepool volume # lvcreate --type cache-pool --size 5G --name fastpool vg /dev/sde Logical volume "fastpool" created.Attach the cachepool to the main logical volume to begin caching: # lvconvert --type cache --cachepoolReplace the following values: fastpool The name of the cachepool volume vg The volume group name mainThe name of the slow logical volume Example 12.4. Attaching the cachepool to the main LV # lvconvert --type cache --cachepool fastpool vg/main Do you want wipe existing metadata of cache pool vg/fastpool? [y/n]: y Logical volume vg/main is now cached.Verification steps Examine the newly created devicevolume with the cache-pool type: # lvs --all --options +devices LV Pool Type Devices [fastpool_cpool] cache-pool fastpool_pool_cdata(0) [fastpool_cpool_cdata] linear /dev/sdf1(4) [fastpool_cpool_cmeta] linear /dev/sdf1(2) [lvol0_pmspare] linear /dev/sdf1(0) main [fastpoool_cpool] cache main_corig(0) [main_corig] linear /dev/sdf1(O)Additional resources lvcreate(8) man page lvmcache(7) man page lvconvert(8) man page 12.5. Enabling dm-writecache caching for a logical volumeThis procedure enables caching of write I/O operations to a logical volume using the dm-writecache method. Prerequisites A slow logical volume that you want to speed up using dm-writecache exists on your system. The volume group that contains the slow logical volume also contains an unused physical volume on a fast block device. If the slow logical volume is active, deactivate it.Procedure If the slow logical volume is active, deactivate it: # lvchange --activate n /Replace the following values: vg The volume group name main-lv The name of the slow logical volumeCreate a deactivated cachevol volume on the fast device: # lvcreate --activate n --size --nameReplace the following values: cachevol-size The size of the cachevol volume, such as 5G fastvol A name for the cachevol volume vg The volume group name /dev/fast-pvThe path to the fast block device, such as /dev/sdf Example 12.5. Creating a deactivated cachevol volume # lvcreate --activate n --size 5G --name fastvol vg /dev/sdf WARNING: Logical volume vg/fastvol not zeroed. Logical volume "fastvol" created.Attach the cachevol volume to the main logical volume to begin caching: # lvconvert --type writecache --cachevolReplace the following values: fastvol The name of the cachevol volume vg The volume group name main-lvThe name of the slow logical volume Example 12.6. Attaching the cachevol volume to the main LV # lvconvert --type writecache --cachevol fastvol vg/main-lv Erase all existing data on vg/fastvol? [y/n]?: y Using writecache block size 4096 for unknown file system block size, logical block size 512, physical block size 512. WARNING: unable to detect a file system block size on vg/main-lv WARNING: using a writecache block size larger than the file system block size may corrupt the file system. Use writecache block size 4096? [y/n]: y Logical volume vg/main-lv now has writecache.Activate the resulting logical volume: # lvchange --activate yReplace the following values: vg The volume group name main-lv The name of the slow logical volumeVerification steps Examine the newly created devices: # lvs --all --options +devices vg LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert Devices main-lv vg Cwi-a-C--- 500.00m [fastvol_cvol] [main-lv_wcorig] 0.00 main-lv_wcorig(0) [fastvol_cvol] vg Cwi-aoC--- 252.00m /dev/sdc1(0) [main-lv_wcorig] vg owi-aoC--- 500.00m /dev/sdb1(0)Additional resources lvmcache(7) man page 12.6. Disabling caching for a logical volumeThis procedure disables dm-cache or dm-writecache caching that is currently enabled on a logical volume. Prerequisites Caching is enabled on a logical volume.Procedure Deactivate the logical volume: # lvchange --activate n /Replace vg with the volume group name, and main-lv with the name of the logical volume where caching is enabled. Detach the cachevol or cachepool volume: # lvconvert --splitcache /Replace the following values: Replace vg with the volume group name, and main-lv with the name of the logical volume where caching is enabled. Example 12.7. Detaching the cachevol or cachepool volume # lvconvert --splitcache vg/main-lv Detaching writecache already clean. Logical volume vg/main-lv writecache has been detached.Verification steps Check that the logical volumes are no longer attached together: # lvs --all --options +devices LV Attr Type Devices fastvol -wi------- linear /dev/fast-pv main-lv -wi------- linear /dev/slow-pvAdditional resources The lvmcache(7) man page |
CopyRight 2018-2019 实验室设备网 版权所有 |